<template>
  <!-- 班级信息页面 -->
  <div class="app-container">
      <!--部门数据-->

    
        <el-form :model="queryParams" ref="queryForm" :inline="true">
          <el-form-item label="采集名称:">
            <el-select
              v-model="queryParams.bigtId"
              placeholder="请选择"
              class="elSelect"
              clearable
            >
              <el-option
                v-for="item in gatherDateList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <el-form-item label="学生姓名:">
              <el-input
                v-model="queryParams.applyName"
                placeholder="请输入学生姓名"
                clearable
              />
            </el-form-item>
          </el-form-item>
          <el-form-item label="注册号:">
            <el-input
              v-model="queryParams.applyRegisterCode"
              placeholder="请输入注册号"
              clearable
            />
          </el-form-item>
          <el-form-item label="班级名称:">
            <el-input
              v-model="queryParams.className"
              placeholder="请输入班级名称"
              clearable
            />
          </el-form-item>
          <el-form-item label="所属院系：" prop="userName">
              <el-select
                v-model="queryParams.deptId"
                placeholder="请选择"
                clearable
                class="elSelect"
                style="width: 100%"
              >
                <el-option
                  v-for="item in deptOptions"
                  :key="item.deptId"
                  :label="item.deptName"
                  :value="item.deptId"
                ></el-option>
              </el-select>
            </el-form-item>
          <el-form-item label="审批状态:">
            <el-select
              v-model="queryParams.apprStatus"
              placeholder="请选择审批状态"
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="dict in dict.type.student_appr_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="申请时间:">
            <el-date-picker
              v-model="dateRange"
              clearable
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>

          <el-form-item style="float: right">
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="query"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="paramsQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['basic:stuapprinfo:add']"
              >新增</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['basic:stuapprinfo:remove']"
              >删除</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              plain
              type="warning"
              size="mini"
              :disabled="multiple"
              @click="dialogVisible = true"
              v-hasPermi="['basic:stuapprinfo:batchappr']"
              >批量审批</el-button
            ></el-col
          >

          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>

        <el-table
          :data="roleList"
          @selection-change="handleSelectionChange"
          v-loading="loading"
        >
          <el-table-column type="selection" width="55"  :selectable="checkSelectable"  align="center" />
          <el-table-column
            label="所在院系"
            prop="collegeName"
            align="center"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="班级"
            prop="className"
            align="center"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="学生姓名"
            prop="applyName"
            align="center"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="注册号"
            prop="applyRegisterCode"
            align="center"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="申请时间"
            prop="applyTime"
            :show-overflow-tooltip="true"
            align="center"
          />
          <el-table-column label="状态" prop="apprStatus" align="center">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.student_appr_status"
                :value="scope.row.apprStatus"
              ></dict-tag>
            </template>
          </el-table-column>
          <el-table-column label="审批记录" align="center" prop="apprStatus">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="viewDetails(scope.row)"
                v-hasPermi="['basic:stuapprinfo:query']"
                >查看审批</el-button
              >
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            fixed="right"
            width="160"
          >
            <template slot-scope="scope">
              <!-- <el-button
            size="mini"
            type="text"
            @click="viewDetails(scope.row)"
            v-hasPermi="['basic:stuapprinfo:query']"
          >查看详情</el-button> -->
              <el-button
                size="mini"
                type="text"
                v-hasPermi="['basic:stuapprinfo:appr']"
                @click="handleExamine(scope.row)"
                v-show="
                  scope.row.apprStatus === '0' && scope.row.hide == false
                  
                "
                >审核</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="handleDelete(scope.row)"
                v-hasPermi="['basic:stuapprinfo:remove']"
                >删除</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="handleEdit(scope.row)"
                v-hasPermi="['basic:stuapprinfo:edit']"
                v-show="scope.row.apprStatus === '3' && scope.row.hide == true"
                >修改</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
    <!-- 新增/修改弹窗 -->
    <studentsIndex
      ref="stuapply"
      :deptOptions="deptOptions"
      :addRessOptions="addRessOptionsList"
      @saveSuccess="submit"
      @savePut="submitPut"
      :title="title"

    >
    </studentsIndex>
    <!-- 审核弹窗 -->
    <examine
      ref="examineForm"
      :addRessOptions="addRessOptionsList"
      @pass="handleCheck"
      @reject="handleReject"
      @refuse="handleRefuse"
    >
    </examine>
    <!-- 查看审批详情 -->
    <el-dialog
      :title="title"
      :visible.sync="beginOpen"
      width="60%"
      append-to-body
    >
      <el-table
        v-loading="loading"
        :data="clrApprRecordList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" align="center" type="index" />
        <el-table-column
          label="审批角色"
          align="center"
          prop="roleName"
        ></el-table-column>
        <el-table-column
          label="审批人"
          align="center"
          prop="apprName"
        ></el-table-column>
        <el-table-column
          label="审批人工号"
          align="center"
          prop="apprTno"
        ></el-table-column>
        <el-table-column
          label="审批时间"
          align="center"
          prop="apprTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.apprTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审批状态" align="center" prop="apprStatus">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.student_appr_status"
              :value="scope.row.apprStatus"
            />
          </template>
        </el-table-column>
        <el-table-column label="审批意见" align="center" prop="apprComment">
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog title="批量审核" :visible.sync="dialogVisible" width="30%">
      <el-form :model="formBatch" label-width="80px">
        <el-form-item label="审核意见">
          <el-input
            v-model="formBatch.reason"
            placeholder="请输入审核意见"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleThrough">同 意</el-button>
        <el-button type="warning" @click="handleRejects">驳 回</el-button>
        <el-button type="danger" @click="handleRefuses">拒 绝</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
            
            <script>
// import { deptTreeSelect } from "@/api/system/user";

import searchForm from "@/components/Search/searchForm.vue";
import { getInfoGatherSelect } from "@/api/flowable/gather.js";

import {
  stuapprinfoList,
  stuapprinfo,
  addersTree,
  apprStatus,
  stuapprinfoDel,
  getInforStuapprinfo,
  batchAppr,
  getApplyNum,
  stuappPut,
} from "@/api/flowable/stuapply.js";
import studentsIndex from "./componet/studentsIndex.vue";
import examine from "./componet/examine.vue";
import { classTree, notPreCollegeSelect } from "@/api/information/studentInfor";
export default {
  name: "Role",
  dicts: [
    "sys_normal_disable",
    "basic_form_type",
    "gather_stauts",
    "student_appr_status",
  ],
  components: { searchForm, studentsIndex, examine },
  data() {
    return {
      tableVersion: 0,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dialogVisible: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 日期范围
      dateRange: [],
      // 部门数据
      professionList: [],
      // 入学年级数据
      gradeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      activeName: "userForm",
      formLabelWidth: "90px",
      input: "",
      deptOptions: [],
      collegeSelectList: [],
      fieldConfig: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bigtId:'',
        applyName: '',
        applyRegisterCode: '',
        className: '',
      },
      // 表单参数
      form: {
        deptId: "",
        classNumber: "",
      },
      formBatch: {
        reason: "",
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
      formType: [],
      classInforList: [], // 基本信息字段表
      awadFormList: [], // 获奖信息字段表
      familyFormList: [], // 家庭信息字段表
      checkedCities: [], // 学生信息多选
      familyFormData: [],
      userFormData: [],
      awadFormData: [],
      checked: false,
      addRessOptionsList: [],
      clrApprRecordList: [],
      gatherDateList: [],
      beginOpen: false,
    };
  },
  computed: {
    userstudent() {
      return this.$store.state.user.userInfor.student;
    },
  },
  created() {
    //     this.getDeptTree();
    // this.getList();
    console.log(this.userstudent, "学生信息");
    notPreCollegeSelect().then((response) => {
      this.deptOptions = response.data;
    });
    addersTree().then((res) => {
      console.log(res, "家庭地址");
      this.addRessOptionsList = res.data;
    });
    getInfoGatherSelect().then((res) => {
      this.gatherDateList = res.data.map((item) => ({
        label: item["BIGT_NAME"],
        value: item["BIGT_ID"],
      }));
       this.queryParams.bigtId = this.gatherDateList[0].value;
      this.getList();
    });
  },
  // 重置
    
  methods: {
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      this.queryParams = Object.assign(this.queryParams, val);
      // console.log(arr);
      this.queryParams.pageNum = 1;
      this.getList();
    },
     query(val) {
      // 查询条件和分页数据合并
      this.queryParams = Object.assign(this.queryParams, val);
      // console.log(arr);
      this.queryParams.pageNum = 1;
       this.getList();
    },
    paramsQuery(data) {
      console.log(data);
      this.queryParams = {
         deptId: null,
      
        bigtId:this.gatherDateList[0].value

      };
      this.dateRange = [];
      // this.queryParams.atSchool = "C";
      // this.queryParams.studentStatus = "A";
      this.queryParams = Object.assign(this.queryParams, data);
      this.getList();
    },
    handleClick() {
      // getFormInfo(this.activeName).then((res) => {
      //   console.log(res, "获取表单填写格式");
      //   this.fieldConfig = res.data
      // });
      console.log(this.userstudent, "传递的数据");
      this.$refs.stuapply.openDia();
      // this.$refs.stuapply.getGradeInfor();
      // this.$refs.stuapply.getSpeciality();
      // this.$refs.stuapply.changeGrade();
    },
// 
    // 驳回修改
    handleEdit(row) {
      const caiId = row.baiId;
      getInforStuapprinfo(caiId).then((response) => {
        // this.form = response.data;
        console.log(this.form, "xiangq");
        this.$nextTick(() => {
          this.$refs.stuapply.openEdit(response.data);
          this.$refs.stuapply.getGradeInfor();
          this.$refs.stuapply.getSpeciality();
          this.$refs.stuapply.changeGrade(); // 确保在 DOM 更新完成后打开弹窗
        });

        // this.handleClick()
        // this.clrApprRecordList = response.data.apprRecordList;
        // this.beginOpen = true;
        // this.title = "查看审批详情";
      });
    },
    submit(data) {
      console.log(data, "huihdhfcjksh");

      stuapprinfo({ parameter: data }).then((res) => {
        this.getList();
        console.log(res, "提交的参数");
        this.$modal.msgSuccess("提交成功");
        this.$refs.stuapply.closeDia();
      });
    },
    submitPut(data) {
      console.log("修改", data);

      stuappPut({
        parameter: JSON.stringify(data),
        baiId: data.baiId,
        apprStatus: data.apprStatus,
        studentId: data.id,
      }).then((res) => {
        this.getList();
        console.log(res, "提交的参数");
        this.$modal.msgSuccess("提交成功");
        this.$refs.stuapply.closeDia();
      });
    },
     checkSelectable(row, index) {
      // 仅当状态为“正常”时，才允许选择
      return row.apprStatus === '0' && row.hide === false;
    },
    // 监听选择变化
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /** 查询审批详情 */
    viewDetails(row) {
      const caiId = row.baiId;
      getInforStuapprinfo(caiId).then((response) => {
        console.log(response, "xiangq");
        this.form = response.data;
        this.clrApprRecordList = response.data.apprRecordList;
        this.beginOpen = true;
        this.title = "查看审批详情";
      });
    },
    // 重置
    onReset(data) {
      console.log(data);
      this.dateRange = [];
      this.queryParams = {};
      this.queryParams = Object.assign(this.queryParams, data);
      this.getList();
    },
    // 清除表单
    CloseIn() {
      this.form = {};
      this.open = false;
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      stuapprinfoList(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.roleList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 审核通过按钮
    handleCheck(data) {
      let checkDate = {
        apprStatus: 1,
        reason: data.reason,
      };
      apprStatus(data.baiId, checkDate).then((res) => {
        this.$refs.examineForm.notDisabled = true;
        console.log(res, "审核成功");
        this.$modal.msgSuccess("审核通过");
        this.getList();
        this.$refs.examineForm.modify = false;
      });
    },
    // 驳回按钮
    handleReject(data) {
      // if (data.reason) {
      //   let checkDate = {
      //     apprStatus: 3,
      //     reason: data.reason,
      //   };
      //   apprStatus(data.baiId, checkDate).then((res) => {
      //     this.$modal.msgSuccess("驳回成功");
      //     this.getList();
      //     this.$refs.examineForm.modify = false;
      //   });
      // } else {
      //   this.$modal.msgError("请填写审核意见！");
      // }

      let checkDate = {
        apprStatus: 3,
        reason: data.reason,
      };
      apprStatus(data.baiId, checkDate).then((res) => {
        this.$modal.msgSuccess("驳回成功");
        this.getList();
        this.$refs.examineForm.modify = false;
      });
    },
    // 审核通过按钮
    handleRefuse(data) {
      let checkDate = {
        apprStatus: 2,
        reason: data.reason,
      };
      apprStatus(data.baiId, checkDate).then((res) => {
        console.log(res, "审核成功");
        this.$modal.msgSuccess("拒绝成功");
        this.getList();
        this.$refs.examineForm.modify = false;
      });
    },
    // 批量审核通过
    handleThrough() {
      let data = {
        apprStatus: 1,
        reason: this.formBatch.reason,
        baiIds: this.ids,
      };
      batchAppr(data).then((res) => {
        this.dialogVisible = false;
        this.$modal.msgSuccess(res.msg);
        this.getList();
        this.formBatch.reason = "";
      });
    },
    // 批量审核驳回
    handleRejects() {
      // if (this.formBatch.reason) {
      //   let data = {
      //     apprStatus: 3,
      //     reason: this.formBatch.reason,
      //     baiIds: this.ids,
      //   };
      //   batchAppr(data).then((res) => {
      //     this.dialogVisible = false;
      //     this.$modal.msgSuccess(res.msg);
      //     this.getList();
      //     this.formBatch.reason = "";
      //   });
      // } else {
      //   this.$modal.msgError("请填写驳回意见");
      // }

      let data = {
        apprStatus: 3,
        reason: this.formBatch.reason,
        baiIds: this.ids,
      };
      batchAppr(data).then((res) => {
        this.dialogVisible = false;
        this.$modal.msgSuccess(res.msg);
        this.getList();
        this.formBatch.reason = "";
      });
    },
    // 批量审核拒绝
    handleRefuses() {
      let data = {
        apprStatus: 2,
        reason: this.formBatch.reason,
        baiIds: this.ids,
      };
      batchAppr(data).then((res) => {
        this.dialogVisible = false;
        this.$modal.msgSuccess(res.msg);
        this.getList();
        this.formBatch.reason = "";
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.baiId);
      this.name = selection.map((item) => item.applyName);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.handleClick();
      this.open = true;
      this.title = "信息采集";
    },
    // 审核
    handleExamine(row) {
      this.$refs.examineForm.examineDialog(row.baiId);
    },

    handleBatch() {
      const roleIds = row.baiId || this.ids;
      this.name = row.applyName || this.name;
      this.$modal
        .confirm('是否确认删除采集名称"' + this.name + '"的数据项？')
        .then(function () {
          return stuapprinfoDel(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    } /** 删除按钮操作 */,
    handleDelete(row) {
      const roleIds = row.baiId || this.ids;
      this.name = row.applyName || this.name;
      this.$modal
        .confirm('是否确认删除采集名称"' + this.name + '"的数据项？')
        .then(function () {
          return stuapprinfoDel(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
      <style scoped>
.sort-container {
  padding: 20px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.modified-hint {
  margin-left: 10px;
  font-size: 12px;
  color: #52c41a;
  background-color: #f6ffed;
  padding: 2px 6px;
  border-radius: 10px;
}
/* 输入框聚焦样式 */
/deep/ .el-input-number.is-active {
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}

/* 表格行高亮 */
/deep/ .el-table__row:hover {
  background-color: #f5f7fa !important;
}

/* 排序输入框特殊样式 */
/deep/ .sort-input-cell .el-input-number {
  transition: all 0.3s ease;
}
</style>